package br.com.array.android.ma.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.array.android.ma.R;
import br.com.array.android.ma.model.Notificacao;

import java.util.List;

/**
 * Created by leonardo.neves on 06/08/2014.
 */
public class NotificacaoAdapter extends ArrayAdapter<Notificacao> {

    private Context context;
    private int resource;

    public NotificacaoAdapter(Context context, int resource, List<Notificacao> objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null){
            convertView = LayoutInflater.from(this.context).inflate(this.resource, parent, false);

            holder = new ViewHolder();
            holder.textViewTitulo = (TextView) convertView.findViewById(R.id.adapter_notificacao_tv_titulo);
            holder.textViewDescricao = (TextView) convertView.findViewById(R.id.adapter_notificacao_tv_descricao);
            holder.textViewData = (TextView) convertView.findViewById(R.id.adapter_notificacao_tv_data);
            holder.imageViewIcone = (ImageView) convertView.findViewById(R.id.adapter_notificacao_iv_icone);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Notificacao notificacao = getItem(position);
        holder.textViewTitulo.setText(notificacao.getTitulo());
        holder.textViewDescricao.setText(notificacao.getDescricao());
        holder.textViewData.setText(notificacao.getData());
        holder.imageViewIcone.setImageResource(notificacao.getIcone());

        return convertView;
    }

    static class ViewHolder {
        TextView textViewTitulo;
        TextView textViewDescricao;
        TextView textViewData;
        ImageView imageViewIcone;
    }

}
